<?php

/* @var $this yii\web\View */

use yii\helpers\Html;
use yii\web\JsExpression;
use daixianceng\echarts\ECharts;
use app\models\Sale;

$this->title = '销售量top';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-saleTop">
<div>
    <?php
    $readonly=true;
    if(\Yii::$app->authManager->checkAccess(Yii::$app->user->id, 'admin'))
    {
        $readonly=false;
    }
    ?>
    <?= Html::label('航空公司或代理人', 'airline', []) ?>
    <?= Html::input('text', 'airline', $airline, ['id'=>'myairline','readonly'=>$readonly]) ?>
    <?= Html::label('时间', 'dayid', []) ?>
    <?= Html::input('text', 'dayid', $dayid, ['id'=>'mydayid']) ?>
    <?= Html::button('查询', ['id' => 'chaxun']) ?>
</div>
<div>
    <?= ECharts::widget([
        'responsive' => true,
        'options' => [
            'style' => 'height: 400%'
        ],
        'pluginOptions' => [
            'option' => [
                'title' => [
                    'text' => '代理人在'.$airline.'销售量top(时间：'.$dayid.')',
                    'x'=>'center'
                ],
                'tooltip' => [
                    'trigger' => 'axis'
                ],
                'legend' => [
                    'orient'=> 'vertical',
                    'left'=> 'left',
                    'data'=> [],
                ],

                'tooltip'=> [
                                'trigger'=> 'item',
                                'formatter'=> "{a} <br/>{b} : {c} ({d}%)"
                            ],
                'series' => [
                            [
                    'name'=> '代理人top',
                    'type'=> 'pie',
                    'radius' => '55%',
                    'center'=> ['50%', '60%'],
                    'data'=>[],
                    'itemStyle'=> [
                            'emphasis'=> [
                                        'shadowBlur'=> 10,
                                        'shadowOffsetX'=> 0,
                                        'shadowColor'=> 'rgba(0, 0, 0, 0.5)'
                                    ]
                    ]
                    ]
                        ]
                    ]
        ]
    ]); ?>
</div>
    <?php $this->beginBlock('myjs') ?>
    function getdata() {
    var echarts_w0 = echarts.init(document.getElementById('w0'));
    echarts_w0.showLoading();
    var airline=$("#myairline").val();
    var dayid=$("#mydayid").val();
    $.ajax({
    type: "POST",
    url: '<?=\Yii::getAlias('@web')?>/site/ajaxtopc',
    dataType: "json",
    data:
    {
    csrfToken:"<?= Yii::$app->request->csrfToken ?>",
    airline:airline,
    dayid:dayid,
    },
    success: function(data)
    {
    echarts_w0.hideLoading();
    echarts_w0.setOption(
    {
    "title": { "text": "代理人在"+data.airline+"销售量top(时间："+dayid+")", "x": "center" },
    "tooltip": { "trigger": "item", "formatter": "{a} <br/>{b} : {c} ({d}%)" },
    "legend":
    {
    "orient": "vertical",
    "left": "left",

    "data":
    data.agent
    },

    "series":
    [
    {
    "name": "代理人top",
    "type": "pie", "radius": "55%", "center": ["50%", "60%"],
    "data":
     data.data,
    "itemStyle": { "emphasis": { "shadowBlur": 10, "shadowOffsetX": 0, "shadowColor": "rgba(0, 0, 0, 0.5)" } } }
    ]
    });
    },
    error: function(jqXHR)
    {
    alert("发生错误：" + jqXHR.status);
    },
    });
    }

    getdata();
    $("#chaxun").click(function(){
    getdata();
    });
    <?php $this->endBlock() ?>
    <?php $this->registerJs($this->blocks['myjs'], \yii\web\View::POS_READY); ?>
</div>
